package com.example.travel.controller;

import com.example.travel.entity.*;
import com.example.travel.entity.dto.*;
import com.example.travel.service.IAdminSelectService;
import com.example.travel.service.IAdminUpdateService;
import com.example.travel.util.ResultUtil;
import com.example.travel.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/AdminUpdateController")
public class AdminUpdateController {

    @Autowired
    private IAdminUpdateService adminUpdateService;

    @Autowired
    private UploadUtil uploadUtil;

    /**
     * 用户审核通过
     * @param user
     * @return
     */
    @PutMapping("/updateUserAudit")
    public boolean updateUserAudit(User user){
        return adminUpdateService.updateUserAudit(user);
    }

    /**
     * 酒店订单办理入住
     * @param orderform
     * @return
     */
    @PutMapping("/updateCheckIn")
    public boolean updateCheckIn(Orderform orderform){
        return adminUpdateService.updateCheckIn(orderform);
    }

    /**
     *  管理员修改订单信息
     * @param orderform
     * @return
     */
    @PutMapping("/updateOrderForm")
    public boolean updateOrderForm(Orderform orderform){
        return adminUpdateService.updateOrderForm(orderform);
    }

    /**
     * 修改酒店信息
     */
    @PostMapping("/updateHotelInformation")
    public boolean updateHotelInformation(HotelDTO hotelDTO) throws IOException {
        if(hotelDTO.getFile() != null){
            String uploadName = uploadUtil.upload(hotelDTO.getFile());
            hotelDTO.setImgAddress(uploadName);
        }
        return adminUpdateService.updateHotelInformation(hotelDTO);
    }

    /**
     * 修改景点订单状态
     * @param orderformDTO
     * @return
     */
    @PutMapping("/updateScenicCheckIn")
    public boolean updateScenicCheckIn(OrderformDTO orderformDTO){
        return adminUpdateService.updateScenicCheckIn(orderformDTO);
    }

    /**
     * 修改景点订单信息
     * @param orderformDTO
     * @return
     */
    @PutMapping("/updateScenicOrderForm")
    public boolean updateScenicOrderForm(OrderformDTO orderformDTO){
        return adminUpdateService.updateScenicOrderForm(orderformDTO);
    }

    /**
     * 修改景点信息
     * @param scenicDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/updateScenicInformation")
    public boolean updateScenicInformation(ScenicDTO scenicDTO) throws IOException {
        if(scenicDTO.getFile() != null){
            String uploadName = uploadUtil.upload(scenicDTO.getFile());
            scenicDTO.setImgAddress(uploadName);
        }
        return adminUpdateService.updateScenicInformation(scenicDTO);
    }

    /**
     * 修改景点轮播图
     * @param scenicImgDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/updateScenicImg")
    public ResultUtil updateScenicImg(ScenicImgDTO scenicImgDTO) throws IOException {
        String uploadName = uploadUtil.upload(scenicImgDTO.getFile());
        scenicImgDTO.setImgAddress(uploadName);
        return ResultUtil.ok(adminUpdateService.updateScenicImg(scenicImgDTO));
    }

    /**
     * 修改节日信息
     * @param festivalDTO
     * @return
     */
        @PutMapping("/updateFestivalInformation")
    public boolean updateFestivalInformation(FestivalDTO festivalDTO){
        return adminUpdateService.updateFestivalInformation(festivalDTO);
    }

    /**
     * 修改节日图片
     * @param festivalDTO
     * @return
     */
    @PostMapping("/updateFestivalImg")
    public ResultUtil updateFestivalImg(FestivalDTO festivalDTO) throws IOException {
        String upload = uploadUtil.upload(festivalDTO.getFile());
        festivalDTO.setImgAddress(upload);
        return ResultUtil.ok(adminUpdateService.updateFestivalImg(festivalDTO));
    }

    /**
     * 回复留言
     * @param leaveDTO
     * @return
     */
    @PutMapping("/updateReplyText")
    public boolean updateReplyText(LeaveDTO leaveDTO){
        return adminUpdateService.updateReplyText(leaveDTO);
    }


}
